<?php 
include("db/connect.php");
if(@$_POST["type"]==1){
	$sqldeletematerial="delete from material where mat_id='".@$_POST["temp"]."'";
	$querydelete=mysql_query($sqldeletematerial);
	}
	else if(@$_POST["type"]==3){
		$sqlupdate="update material set mat_name='".@$_POST["mat_name"]."',mat_price='".@$_POST["mat_price"]."',mat_unit='".@$_POST["mat_unit"]."' where mat_id='".@$_POST["temp"]."'";
		$queryupdatematerial=mysql_query($sqlupdate);
		}
		$sqlselectmaterial="select * from material";
		$sqlselectmaterial.=" group by mat_id";
		$queryselectmaterial=mysql_query($sqlselectmaterial);
?>
<table width="100%" height="132" border="1">
  <tr>
    <th width="15%">ชื่อสินค้า</th>
    <th width="9%">ราคา</th>
    <th width="9%">หน่วย</th>
    <th width="7%">แก้ไข</th>
    <th width="6%">ลบ</th>
    <th width="10%">ยื่นอนุมัติการสั่งซื้อ</th>
  </tr>
  <?php 
  while($resultmaterial=@mysql_fetch_array($queryselectmaterial)){
  ?>
  <tr>
    <td><?php echo $resultmaterial["mat_name"]?></td>
    <td><?php echo $resultmaterial["mat_price"]?></td>
    <td><?php echo $resultmaterial["mat_unit"]?></td>
    <td><a href="Javascript:ajaxmanage(2,<?php echo $resultmaterial["mat_id"];?>);">แก้ไข</a></td>
    <td><a href="Javascript:ajaxmanage(1,<?php echo $resultmaterial["mat_id"];?>);" onclick="return window.confirm('ต้องการลบใช่ไหม')">ลบ</a></td>
    <td><a href="Javascript:ajaxmanage(5,<?php echo $resultmaterial["mat_id"];?>);">ยื่นอนุมัติการสั่งซื้อ</a></td>
  </tr>
  <?php }?>
</table>
<script>
 $(function() {
		/* For zebra striping */
        $("table tr:nth-child(odd)").addClass("odd-row");
		/* For cell text alignment */
		$("table td:first-child, table th:first-child").addClass("first");
		/* For removing the last border */
		$("table td:last-child, table th:last-child").addClass("last");
});</script>